/*
*
* bounding_box.cpp
* maybe one of the most basic system for collisions
*
*/

#include "bounding_box.h"

/* Constructor 1
*
*/
BoundingBox::BoundingBox() { _bbx1 = _bby1 = _bbx2 = _bby2 = _bbs = _bblock = 0; }

/* Constructor 2
*   @arg:
*     - int x1 : Top-Left corner X's value
*     - int y1 : Top-Left corner Y's value
*     - int x2 : Bottom-Right corner X's value
*     - int y2 : Bottom-Right corner Y's value
*/
BoundingBox::BoundingBox( int x1, int y1, int x2, int y2) {
  _bbs = 1;
  __setBoundingBox(x1, y1, x2, y2); // Yeah, why not?
}

/*  __setBoundingBox() 1 : Defines the Bounding Box size
*   @arg:
*     - int x1 : Top-Left corner X's value
*     - int y1 : Top-Left corner Y's value
*     - int x2 : Bottom-Right corner X's value
*     - int y2 : Bottom-Right corner Y's value
*/
void BoundingBox::__setBoundingBox(int x1, int y1, int x2, int y2) {
  if ( _bblock ) return;
  _bbx1 = x1;
  _bby1 = y1;
  _bbx2 = x2;
  _bby2 = y2;
  if ( x1 > x2 ) {
    _bbx1 = x2;
    _bbx2 = x1;
  }
  if ( y1 > y2 ) {
    _bby1 = y2;
    _bby2 = y1;
  }
}

/*  __setBoundingBox() 2 : Defines the Bounding Box size
*   @arg:
*     - BoundingBox nbb : the BoundingBox source
*/
void BoundingBox::__setBoundingBox(BoundingBox nbb) {
  if ( _bblock == 1 ) return;
  _bbx1 = nbb._bbx1;
  _bby1 = nbb._bby1;
  _bbx2 = nbb._bbx2;
  _bby2 = nbb._bby2;
}


/*  __enableBoundingBox() : Ignore bounding box if set to 0
*   @arg:
*     - int s : set the status to either on (s = 1) or off (s = {* \ 1})
*   @tip:
*     - useful because when using collidesWith(), it will always return false if it's set to off
*/
void BoundingBox::__enableBoundingBox(int s) { _bbs = ( s == 1 ) ? 1 : 0; }

/*  __lockBoundingBox : Ignore _setBoundingBox() calls if set to 1
*   @arg:
*     - int s : 1=Locked/0=Unlocked
*/
void BoundingBox::__lockBoundingBox(int s) { _bblock = ( s == 1 ) ? 1 : 0; }
